package com.fzshang.shopping.commen.serviceImpl;

import cn.hutool.crypto.digest.DigestUtil;
import com.fzshang.shopping.commen.bean.Classification;
import com.fzshang.shopping.commen.bean.UserInfo;
import com.fzshang.shopping.commen.bean.layuiBean.ResultPage;
import com.fzshang.shopping.commen.bean.layuiBean.VoPage;
import com.fzshang.shopping.commen.bean.request.Sale;
import com.fzshang.shopping.commen.mapper.UserInfoMapper;
import com.fzshang.shopping.commen.service.UserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzshang.shopping.commen.util.data.Date;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 后台用户 服务实现类
 * </p>
 *
 * @author 冯政尚
 * @since 2020-03-03
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    /**
     * @param account
     * @param passWord
     * @return 登陆
     */
    @Override
    public UserInfo UserLogin(String account, String passWord) {

        return baseMapper.userLogin(account,passWord);
    }
    /**
     * @param requestUserName
     * @return 判断是否有这个用户名
     */
    @Override
    public UserInfo userNameIsNall(String requestUserName) {
        return baseMapper.userNameIsNall(requestUserName);
    }
    /**
     * @param requestUserName
     * @param requestPassWord
     * @return 判断用户名对应的密码是否正确
     */
    @Override
    public UserInfo passWordIsNall(String requestUserName, String requestPassWord) {
        return baseMapper.passWordIsNall(requestPassWord,requestUserName);
    }

    /**
     * @param voPage
     * @return 商家管理
     */
    @Override
    public ResultPage<UserInfo> selectMyPage(VoPage voPage, UserInfo userInfo) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1) * voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("account", userInfo.getAccount());
        paramMap.put("idNumber", userInfo.getIdNumber());
        List<UserInfo> list = baseMapper.selectMyPage(paramMap);
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<UserInfo> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    /**
     * @param voPage
     * @return 商家审核
     */
    @Override
    public ResultPage<UserInfo> selectMyPage1(VoPage voPage, UserInfo userInfo) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1) * voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("account", userInfo.getAccount());
        paramMap.put("idNumber", userInfo.getIdNumber());
        List<UserInfo> list = baseMapper.selectMyPage1(paramMap);
        Integer count = baseMapper.countMyPage1(paramMap);
        ResultPage<UserInfo> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    /**
     * @return 商家统计
     * @throws Exception
     */
    @Override
    public List<Sale> selectMoney() throws Exception {
        //查询当前系统日期所有年份
        List list = Date.getThisYearFirstDayAndTheLastDay();
        List<Sale>  list1 =new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            Double a = baseMapper.selectByTimeSumMoney((String) list.get(i));
            Sale sale = new Sale();
            sale.setNum(a);
            sale.setTime(list.get(i)+"");
            list1.add(sale);
        }
        for (int i = 0; i < list1.size(); i++) {
            if(list1.get(i).getNum()==null){
                list1.get(i).setNum(0.0);
            }
        }
        return list1;
    }

    /**
     * @return 销售统计
     * @throws Exception
     */
    @Override
    public List<Sale> selectMoneySale() throws Exception {
        //查询当前系统日期所有年份
        List list = Date.getThisYearFirstDayAndTheLastDay();
        List<Sale>  list1 =new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            Double a = baseMapper.selectByTimeSumMoneySale((String) list.get(i));
            Sale sale = new Sale();
            sale.setNum(a);
            sale.setTime(list.get(i)+"");
            list1.add(sale);
        }
        for (int i = 0; i < list1.size(); i++) {
            if(list1.get(i).getNum()==null){
                list1.get(i).setNum(0.0);
            }
        }
        return list1;
    }


}
